<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>编辑项目负责人信息</title>
<%@ include file="/common/meta.jsp"%>
<script type="text/javascript" src="${res}/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript" src="${res}/js/validate/irisvalidator.js"></script>
<script type="text/javascript" src="${res}/js/autodisckey/autodisckey.js"></script>

<style type="text/css">
	.input_width { width:130px }
	.select_width { width:143px }
	.table_td td {border:0}
	.long_input{ width:642px }
    .selectWidth4{width:624px;}
</style>
<script type="text/javascript">
var parent_ferTable=parent.$("#orgInfo1");//读取父页面基本信息表格

var v_psn_code="";

$(function(){
	$("#fragment-tab1 :text,#fragment-tab1 [type='date']").addClass("input_width");
	
		
	$("input:not(:radio:button),textarea").each(function(){

		var id=$(this).attr("name");
		if(id==null || id=="")
			return true;
		
		var parentObj=parent_ferTable.find("[name$='/"+id+"']");
		var value="";
		if(parentObj.is("span"))
			value=parentObj.text();
		else
			value=parentObj.val();
		//if($(this).is("input"))//初始化input框 不包括radio
		$(this).val(value);
	});
	
	tree();
	
	function savePsn(){
		//填写检查接口
		validate($("#fragment-tab1"),"");
		if(!valResult()){
			irisValShowMsg($("#savePsn"));
			return false;
		}
		$(".wBox_popup").hide();
		if(confirm("保存成功，是否返回申请书页面")){
			$("input:not(:radio:button),textarea").each(function(){
				
				var id=$(this).attr("name");
				var parentObj=null;
				
				if(id==null || id=="")
					return true;
				
				var parentObj=parent_ferTable.find("[name$='/"+id+"']");

				if(parentObj!=null){
					if(parentObj.is("span")){
						parentObj.text($(this).val());	//将值写回父页面
					}
					else{
						parentObj.val($(this).val());
					}
				}
			});
			
			//修改父页面psn_code节点值
			$(parent.document).find("input[name$='psn_code']").val(v_psn_code);
			parent.tb_remove();
		}
		
	}
	
	$("#savePsn").click(function(){
		setTimeout(savePsn,100);
	});
	
});
var my_prof_title_name="";

//选择项目负责人回调
function selectPsnCall(data) {
	//$(parent.document).find("input[name$='psn_code']").val(data.person.psnCode);
	v_psn_code=data.person.psnCode;
	$("input[name='fzr_name']").val(data.person.zhName);
	$("input[name='fzr_position']").val(data.personExtend.basic_info.position);
	var v=data.personExtend.basic_info.card_type_value;
	if(v=='1'){
		$("input[name='fzr_card_code']").val(data.personExtend.basic_info.card_code);
		var now_year=$("#now_yearqhh").val();
		countAge($("#fzr_card_code").val(),now_year);
	}else{
		$("input[name='fzr_card_code']").val("");
		$("#fzr_age").val("");
	}
	$("input[name='fzr_tel']").val(data.personExtend.contact.tel_work);

	$("#prof_title").val(data.personExtend.basic_info.prof_title_name);
	$("input[name='prof_title_value']").val(data.personExtend.basic_info.prof_title_value);
	$("input[name='prof_title_name']").val(data.personExtend.basic_info.prof_title_name);
	
	$("input[name='fzr_mobile']").val(data.personExtend.contact.mobile);
	$("input[name='fzr_email']").val(data.personExtend.contact.email);

	tree();
	
	tb_remove2();
}

function tree(){
	var prof_title_name=$("#prof_title_name").val(); 
	$("#prof_title").val(prof_title_name);
	$("#prof_title_hideId").val($("#prof_title_value").val());
	$("#prof_title_hideName").val(prof_title_name);
}

function initTreeValueExt(treeId, treeNode) {
	  if (!(treeNode && (treeNode.level > 0 || !treeNode.isParent))) {
		scmWarn($("#" + treeId).attr("label") + messageTip.researchAreaInvalidDisciplineCode);
		if (treeNode.level == 0) {
			$("#" + treeId).val("");
			$("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId+ "_code']").val("");
			$("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId+ "_value']").val("");
			$("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId+ "_name']").val("");
		}
		
		return false;
		}
	
	
		var str = treeNode.name;
		if(treeId=="prof_title"){
			my_prof_title_name=treeNode.name;
		}
		var obj = treeNode.parentNode;
		while (obj != null) {
			obj = obj.parentNode;
		}
		
		$("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId+ "_code']").val(treeNode.id);
		$("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId+ "_value']").val(treeNode.id);
		$("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId+ "_name']").val(str);
		
	}
	
	

function countAge(id_card,now_year){
	//根据身份证号吗自动计算年龄
	if(checkCidInfo(id_card)){
		var year=id_card.substring(6,10);
		$("#fzr_age").val(now_year-year);
	}else{
		$("#fzr_age").val("");
	}
}


//校验身份证号码是否正确
function checkCidInfo(sId) {
	var iSum = 0;
	if (!/^\d{17}(\d|x)$/i.test(sId))
		return false;
	sId = sId.replace(/x$/i, "a");
	if (aCity[parseInt(sId.substr(0, 2))] == null)
		return false;
	sBirthday = sId.substr(6, 4) + "-" + Number(sId.substr(10, 2)) + "-"
			+ Number(sId.substr(12, 2));
	var d = new Date(sBirthday.replace(/-/g, "/"));
	if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d
			.getDate()))
		return false;
	for ( var i = 17; i >= 0; i--)
		iSum += (Math.pow(2, i) % 11) * parseInt(sId.charAt(17 - i), 11);
	if (iSum % 11 != 1)
		return false;
	return true;
}

	
</script>
<script type="text/javascript">

</script>
</head>
<body>
	<input type="hidden" value="${year }" id="now_yearqhh" />
	
	<div class="tab_box" id="fragment-tab1">
		<table class="t_css" width="100%" border="0" cellpadding="0" label="个人信息" cellspacing="1">
		<tr>
			<td nowrap align="right">姓名：</td>
			<td width="350px">
				<input name="fzr_name" disabled="disabled" id="fzr_name" label="姓名" type="text" class="input_text required maxlength:25" value="" maxlength="25"/>
				<security:authorize ifAnyGranted="A_DAILU_PROPOSAL">
					<span id="personSelect">
					<input type="button" class="button_02" style="height: 25px; padding: 1px;" id="selectPsn" value="设置">
					<cpt:personSelect key="personSelect" addRole="3" psnCode="${param.psnCode }" callback="selectPsnCall" bindEvent="click" bindObject="selectPsn" title="设置项目负责人" fltFile="personSelector.ftl"></cpt:personSelect>
					</span>
				</security:authorize>
			</td>
			</td>
			<td align="right">职    务：</td>
			<td>
				<input type="text" name="fzr_position" id="fzr_position" maxlength="20" label="职务" />
			</td>
		</tr>
			
		<tr>
			<td align="right"><span class="color_red">*</span>年    龄：</td>
			<td>
			<input type="text" disabled="disabled" label="年龄" name="fzr_age" id="fzr_age" class="required" maxlength="3"/>
			</td>
			<td align="right"><span class="color_red">*</span>身份证号：</td>
			<td>
				<input type="text" label="身份证号" name="fzr_card_code" id="fzr_card_code" class="required idCard" maxlength="18" onblur="countAge(this.value,${year});"/>
			</td>
		</tr>
		
		<tr>
			<td align="right"><span class="color_red">*</span>电话号码：</td>
			<td>
				<input type="text" name="fzr_tel" id="fzr_tel" maxlength="20" required class="required" label="电话号码" />
			</td>
		
			<td align="right"><span class="color_red">*</span>职称：</td>
			<td>
			<cpt:tree key="prof_title" cacheable="false" readonly="true" value="" id="prof_title" name="prof_title"  showPattern="all" shieldPattern="-1" onClick="initTreeValueExt"   label="职称" />
			<input type="hidden" id="prof_title_value" name="prof_title_value" value="" class="required"  label="职称"/> 
			<input type="hidden" id="prof_title_name" name="prof_title_name" value="" />
			</td>
		</tr>
		<tr>
			<td align="right"><span class="color_red">*</span>手机：</td>
			<td>
				<input type="text" id="fzr_mobile" name="fzr_mobile" maxlength="11" onfocus="InitInput.setNumber(this,11,0,0);" class="required mobile"   label="手机" />
			</td>
			<td align="right"><span class="color_red">*</span>E-mail：</td>
			<td>
				<input type="text" name="fzr_email" id="fzr_email" required class="required email" label="E-mail" />
			</td>
		</tr>
	</table>
	</div>
	<table width="100%" align="center">
		<tr>
			<td><input type="button"  class="button_01 notdisabled" id="savePsn" value="保存">
				&nbsp;<input type="button" id="cancel" class="button_01 notdisabled" value="取消" onclick="parent.tb_remove();">
			</td>
		</tr>
	</table>
	<br />
</body>
</html>